package com.onlinevideo.dao.impl;

import com.onlinevideo.dao.BaseDao;
import com.onlinevideo.dao.CommentDao;
import com.onlinevideo.entity.Comment;

import java.util.List;

public class CommentDaoImpl extends BaseDao implements CommentDao {
    @Override
    public int insert(Comment comment) {
        String sql = "INSERT INTO `T_comment` (`comment_id`,`father_comment_id`,`user_id`,`video_id`,`comment_content`,`comment_time`,`comment_Status`) VALUES (?,?,?,?,?,?,?)";
        return super.update(sql, comment.getCommentId(), comment.getFatherCommentId(), comment.getUserId(), comment.getVideoId(), comment.getCommentContent(), comment.getCommentTime(), comment.getCommentStatus());
    }

    @Override
    public int delete(Long id) {
        String sql = "DELETE FROM `T_comment` WHERE `id`=?";
        return super.update(sql, id);
    }


    @Override
    public int deleteByFid(Long fid) {
        String sql = "DELETE FROM `T_comment` WHERE `father_comment_id`=?";
        return super.update(sql, fid);
    }

    @Override
    public int deleteByVid(Long vid) {
        String sql = "DELETE FROM `T_comment` WHERE `video_id`=?";
        return super.update(sql, vid);
    }

    @Override
    public int update(Comment comment) {
        String sql = "UPDATE `T_comment` SET `comment_id`=?,`father_comment_id`=?,`user_id`=?,`video_id`=?,`comment_content`=?,`comment_time`=?,`comment_Status`=? WHERE `id`=?";
        return super.update(sql, comment.getCommentId(), comment.getFatherCommentId(), comment.getUserId(), comment.getVideoId(), comment.getCommentContent(), comment.getCommentTime(), comment.getCommentStatus(), comment.getId());
    }

    @Override
    public Comment queryById(Long id) {
        String sql = "SELECT `id`,`comment_id` AS `commentId`,`father_comment_id` AS `fatherCommentId`,`user_id` AS `userId`,`video_id` AS `videoId`,`comment_content` AS `commentContent`,`comment_time` AS `commentTime` ,`comment_status` AS `commentStatus` FROM `T_comment` WHERE 1=1 AND `id`=? ";
        return super.queryForOne(Comment.class, sql, id);
    }

    @Override
    public List<Comment> queryAll() {
        String sql = "SELECT `id`,`comment_id` AS `commentId`,`father_comment_id` AS `fatherCommentId`,`user_id` AS `userId`,`video_id` AS `videoId`,`comment_content` AS `commentContent`,`comment_time` AS `commentTime` ,`comment_status` AS `commentStatus` FROM `T_comment` WHERE 1=1";
        return super.queryForList(Comment.class, sql);
    }

    @Override
    public List<Comment> queryByVideoId(Long id) {
        String sql = "SELECT `id`,`comment_id` AS `commentId`,`father_comment_id` AS `fatherCommentId`,`user_id` AS `userId`,`video_id` AS `videoId`,`comment_content` AS `commentContent`,`comment_time` AS `commentTime` ,`comment_status` AS `commentStatus` FROM `T_comment` WHERE 1=1 AND `video_id`=?";
        return super.queryForList(Comment.class, sql, id);
    }

    @Override
    public Comment queryByCommentId(Long commentId) {
        String sql = "SELECT `id`,`comment_id` AS `commentId`,`father_comment_id` AS `fatherCommentId`,`user_id` AS `userId`,`video_id` AS `videoId`,`comment_content` AS `commentContent`,`comment_time` AS `commentTime` ,`comment_status` AS `commentStatus` FROM `T_comment` WHERE 1=1 AND `comment_id`=?";
        return super.queryForOne(Comment.class, sql,commentId);
    }

    @Override
    public List<Comment> queryByFatherId(Long fatherId) {
        String sql = "SELECT `id`,`comment_id` AS `commentId`,`father_comment_id` AS `fatherCommentId`,`user_id` AS `userId`,`video_id` AS `videoId`,`comment_content` AS `commentContent`,`comment_time` AS `commentTime` ,`comment_status` AS `commentStatus` FROM `T_comment` WHERE 1=1 AND `father_comment_id`=?";
        return super.queryForList(Comment.class, sql,fatherId);
    }


    @Override
    public List<Comment> queryByFatherIdS1(Long fatherId) {
        String sql = "SELECT `id`,`comment_id` AS `commentId`,`father_comment_id` AS `fatherCommentId`,`user_id` AS `userId`,`video_id` AS `videoId`,`comment_content` AS `commentContent`,`comment_time` AS `commentTime` ,`comment_status` AS `commentStatus` FROM `T_comment` WHERE 1=1 AND `father_comment_id`=? AND `comment_status`=1";
        return super.queryForList(Comment.class, sql,fatherId);
    }

    @Override
    public List<Comment> queryByVideoIdS1(Long id) {
        String sql = "SELECT `id`,`comment_id` AS `commentId`,`father_comment_id` AS `fatherCommentId`,`user_id` AS `userId`,`video_id` AS `videoId`,`comment_content` AS `commentContent`,`comment_time` AS `commentTime` ,`comment_status` AS `commentStatus` FROM `T_comment` WHERE 1=1 AND `video_id`=?  AND `comment_status`=1";
        return super.queryForList(Comment.class, sql, id);
    }

    @Override
    public List<Comment> queryAllS0() {
        String sql = "SELECT `id`,`comment_id` AS `commentId`,`father_comment_id` AS `fatherCommentId`,`user_id` AS `userId`,`video_id` AS `videoId`,`comment_content` AS `commentContent`,`comment_time` AS `commentTime` ,`comment_status` AS `commentStatus` FROM `T_comment` WHERE 1=1 AND `comment_status`=0";
        return super.queryForList(Comment.class, sql);
    }

    @Override
    public List<Comment> queryAllS1() {
        String sql = "SELECT `id`,`comment_id` AS `commentId`,`father_comment_id` AS `fatherCommentId`,`user_id` AS `userId`,`video_id` AS `videoId`,`comment_content` AS `commentContent`,`comment_time` AS `commentTime` ,`comment_status` AS `commentStatus` FROM `T_comment` WHERE 1=1 AND `comment_status`=1";
        return super.queryForList(Comment.class, sql);
    }

    @Override
    public List<Comment> queryByFatherIdS0(Long fatherId) {
        String sql = "SELECT `id`,`comment_id` AS `commentId`,`father_comment_id` AS `fatherCommentId`,`user_id` AS `userId`,`video_id` AS `videoId`,`comment_content` AS `commentContent`,`comment_time` AS `commentTime` ,`comment_status` AS `commentStatus` FROM `T_comment` WHERE 1=1 AND `father_comment_id`=?  AND `comment_status`=0";
        return super.queryForList(Comment.class, sql,fatherId);
    }

    @Override
    public List<Comment> queryByVideoIdS0(Long id) {
        String sql = "SELECT `id`,`comment_id` AS `commentId`,`father_comment_id` AS `fatherCommentId`,`user_id` AS `userId`,`video_id` AS `videoId`,`comment_content` AS `commentContent`,`comment_time` AS `commentTime` ,`comment_status` AS `commentStatus` FROM `T_comment` WHERE 1=1 AND `video_id`=?  AND `comment_status`=0";
        return super.queryForList(Comment.class, sql, id);
    }


}

